package com.itheima.web.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Comment;
import com.itheima.domain.Movies;
import com.itheima.service.CommentService;
import com.itheima.service.MoviesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/single")
public class SingleController {
    @Autowired
    private MoviesService moviesService;
    @Autowired
    private CommentService commentService;
    //根据id查找电影
    @GetMapping("/findById")
    public Movies findById(Integer id){
        return moviesService.findById(id);
    }
    //根据id查到评论
    @GetMapping("/findCommentById")
    public PageInfo<Comment> findCommentById(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize,Integer movieId){
        return commentService.findByPage(pageNum,pageSize,movieId);
    }
    //保存评论
    @PostMapping("/saveComment")
    public String saveComment(@RequestBody Comment comment){
        //调用方法
        commentService.save(comment);
        return "ok";
    }

}
